package com.xsdl.factory;


public class Main {

    public static void main(String[] args) {
        load("aaa.json");
    }

    public static RuleConfig load(String ruleConfigFilePath) {
        String ruleConfigFileExtension = getFileExtension(ruleConfigFilePath);
        IRuleConfigParserFactory parserFactory = Constants.cachedMap.get(ruleConfigFileExtension);
        if (parserFactory == null) {
            throw new IllegalArgumentException("Rule config file format is not supported: " + ruleConfigFileExtension);
        }
        IRuleConfigParser parser = parserFactory.createParser(ruleConfigFileExtension);
        String configText = "";
        //从 ruleConfigFilePath 文件中读取配置文本到 configText 中
        RuleConfig ruleConfig = parser.parse(configText);
        return ruleConfig;
    }

    private static String getFileExtension(String filePath) {
        if (filePath == null || filePath.isEmpty()) {
            throw new IllegalArgumentException("filePath is null or empty");
        }
        //...解析文件名获取扩展名，比如 rule.json，返回 json
        String[] strings = filePath.split("\\.");
        return strings[strings.length - 1];
    }

}